/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { Button, Popconfirm, PopconfirmProps } from 'antd';
import React from 'react';
import styles from './bar.less';

interface BarProps {
  withConfirm?: boolean;
  disabled?: boolean;
  loading?: boolean;
  onClick?: React.DOMAttributes<HTMLAnchorElement>['onClick'];
  title?: PopconfirmProps['title'];
}

const Bar: React.FC<BarProps> = (props) => {
  const { withConfirm, onClick, title, loading, disabled } = props;

  if (withConfirm) {
    return (
      <Popconfirm disabled={disabled} title={title} onConfirm={(e) => onClick!(e as any)}>
        <Button className={styles.bar} loading={loading} type='link' disabled={disabled}>
          {props.children}
        </Button>
      </Popconfirm>
    );
  }

  return (
    <Button className={styles.bar} loading={loading} type='link' onClick={onClick}>
      {props.children}
    </Button>
  );
};

export default Bar;
